<template>
    <div class="main">
        <el-card class="box-card">
            <el-form :inline="true" :model="page" class="demo-form-inline">
                <el-form-item label="商家名称">
                    <el-input v-model="page.storeName" placeholder="请输入商家名称" />
                </el-form-item>
                <el-form-item label="提现方式">
                    <el-select v-model="page.presentationMethod" placeholder="请选择">
                        <el-option label="微信" value="微信" />
                        <el-option label="银行卡" value="银行卡" />
                    </el-select>
                </el-form-item>
                <el-form-item label="状态">
                    <el-select v-model="page.states" placeholder="请选择">
                        <el-option label="待审核" value="待审核" />
                        <el-option label="带打款" value="带打款" />
                        <el-option label="已打款" value="已打款" />
                        <el-option label="已驳回" value="已驳回" />
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">搜索</el-button>
                    <el-button type="primary" @click="reset">重置</el-button>
                    <el-button type="primary" @click="reset">导出列表</el-button>
                </el-form-item>
            </el-form>
            <el-table :data="tableData" style="width: 100%" ref="multipleTableRef" max-height="600px">
                <el-table-column type="index" width="55" />
                <el-table-column prop="sort" label="名称" align="center" />
                <el-table-column label="用户" align="center">
                    <template #default="scope">
                        <img :src="scope.row.logo" alt="" style="width: 50px;height: 50px;" v-if="scope.row.logo">
                        <span>-</span>
                    </template>
                </el-table-column>
                <el-table-column prop="storeName" label="体现方式" align="center" />
                <el-table-column prop="productNum" label="体现信息" align="center" />
                <el-table-column prop="shopNum" label="申请金额" align="center" />
                <el-table-column prop="clerkNum" label="状态" align="center" />
                <el-table-column prop="createTime" label="申请时间" align="center" />
                <el-table-column fixed="right" label="操作" width="160">
                    <template #default="scope">
                        <el-button link type="danger" size="small" @click="delData(scope.row)">入账账单</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <Pagination v-if="total != 0" :page="page" :total="total" @pageSizeChanged="handlePageSizeChange"
                @currentPageChanged="handleCurrentPageChange" />
        </el-card>
    </div>
</template>

<script setup>
import { onMounted, reactive, ref } from "vue";
import { getMerchantCenterList, deleteMerchantCenter } from '@/api/merchantManagement.js'
import Pagination from '@/components/pagination/index.vue' // 引入分页组件
import { ElMessage, ElMessageBox } from 'element-plus'

const page = reactive({
    storeName: "",
    presentationMethod: "",
    states: "",
    pageNum: 1,
    pageSize: 10
})
const total = ref(0)
const tableData = reactive([])
// 搜索
const onSubmit = () => {
    getList()
}
// 重置
const reset = () => {
    page.storeName = "";
    page.presentationMethod = "";
    page.states = "";
    page.pageNum = 1;
    page.pageSize = 10;
    getList()
}
// 分页
const handlePageSizeChange = (val) => {
    page.pageNum = 1
    page.pageSize = val
    getList()
}

const handleCurrentPageChange = (val) => {
    page.pageNum = val
    // page.pageSize = 10
    getList()
}


// 删除
const delData = (scope) => {
    ElMessageBox.confirm(
        '是否删除该条数据?',
        '删除',
        {
            confirmButtonText: 'OK',
            cancelButtonText: '取消',
            type: 'warning',
        }
    )
        .then(() => {
            deleteMerchantCenter(scope.id).then(res => {
                if (res.code == 200) {
                    ElMessage({
                        type: 'success',
                        message: '删除成功',
                    })
                    getList()
                }
            })

        })
        .catch(() => {
            ElMessage({
                type: 'info',
                message: '已取消',
            })
        })
}

// 获取列表
const getList = () => {
    tableData.length = 0;
    total.value = 0
    getMerchantCenterList(page).then(res => {
        if (res.code == 200) {
            tableData.push(...res.data.records)
            total.value = res.data.total
        }
    })
}




onMounted(() => {
    getList()
})
</script>

<style lang="scss" scoped>
.box-card ::v-deep .el-select__wrapper {
    width: 100px;
}

.main {
    padding: 0 5px 5px 5px;
}
</style>